﻿* Encoding: UTF-8.

PRESERVE.
begin program python3.
import tempfile, spss, random, spssaux
try:
    tempdir = tempfile.gettempdir()
    spss.Submit(r"""CD "%s".""" % tempdir)
    spss.Submit("""SET PRINTBACK=OFF MPRINT=OFF.""")
    activeds = spss.ActiveDataset()
    if activeds == "*":
        activeds = "D" + str(random.random()+.01)
        spss.Submit("DATASET NAME %s" % activeds)
    wtvar=spss.GetWeightVar()
    if wtvar == None:
        spss.Submit(r"""
USE ALL.
SAVE OUTFILE='Quade_temp.sav'
  /KEEP=MCID_Achieved Difference_CL preop_C2_C7_Lordosis.
GET FILE='Quade_temp.sav'.""")
    else:
        spss.Submit(r"""
DO IF %s >= 1.""" % wtvar)
        spss.Submit(r"""
+ LOOP #i=1 TO %s.""" % wtvar)
        spss.Submit(r"""
XSAVE OUTFILE='Quade_temp.sav'
  /KEEP=MCID_Achieved Difference_CL preop_C2_C7_Lordosis
  /DROP=%s.""" % wtvar)
        spss.Submit(r"""
+ END LOOP.
END IF.
EXECUTE.
GET FILE='Quade_temp.sav'.""")
    spss.Submit(r"""
COUNT miss__=MCID_Achieved Difference_CL preop_C2_C7_Lordosis (MISSING).
SELECT IF miss__=0.
SORT CASES BY MCID_Achieved.
DATASET DECLARE Quade_temp1.
AGGREGATE
  /OUTFILE='Quade_temp1'
  /PRESORTED
  /BREAK=MCID_Achieved
  /N_BREAK=N.
OMS /SELECT ALL EXCEPT=WARNINGS 
  /IF COMMANDS=['Matrix'] 
  /DESTINATION VIEWER=NO
  /TAG='Quade_NoMatrix'.
DATASET DECLARE Quade_out1 WINDOW=HIDDEN.
DATASET DECLARE Quade_out2 WINDOW=HIDDEN.
MATRIX.
GET data
  /VARIABLES=MCID_Achieved Difference_CL preop_C2_C7_Lordosis.
COMPUTE n=NROW(data).
COMPUTE g=DESIGN(data(:,1)).
COMPUTE dfh=NCOL(g)-1.
COMPUTE dfe=n-NCOL(g).
COMPUTE y=RNKORDER(data(:,2)).
COMPUTE ncov=NCOL(data)-2.
COMPUTE x=MAKE(n,1,1).
LOOP #j=1 TO ncov.
+ COMPUTE x={x,RNKORDER(data(:,#j+2))}.
END LOOP.
COMPUTE y=y-x*INV(SSCP(x))*T(x)*y.
COMPUTE sst=MSSQ(y).
COMPUTE sse=MSSQ(y-g*INV(SSCP(g))*T(g)*y).
COMPUTE ssh=sst-sse.
COMPUTE fstat=(ssh/dfh)/(sse/dfe).
COMPUTE pval=1-FCDF(fstat,dfh,dfe).
SAVE {fstat,dfh,dfe,pval}
   /OUTFILE='Quade_out1'
   /VARIABLES=F,DFH,DFE,sig.
COMPUTE countvec=T(CSUM(g)).
COMPUTE grpmean=T(g)*y&/countvec.
COMPUTE k=NROW(grpmean).
COMPUTE diff=MAKE(k*(k-1)/2,1,0).
COMPUTE sediff=MAKE(k*(k-1)/2,1,0).
COMPUTE h=1.
LOOP i=1 TO k-1.
+  LOOP j=i+1 TO k.
+    COMPUTE diff(h)=grpmean(i)-grpmean(j).
+    COMPUTE sediff(h)=SQRT((sse/dfe)*(1/countvec(i)+1/countvec(j))).
+    COMPUTE h=h+1.
+  END LOOP.
END LOOP.
COMPUTE tvec=diff&/sediff.
COMPUTE dfvec=MAKE(NROW(tvec),1,dfe).
COMPUTE pvec=MAKE(NROW(tvec),1,1)-FCDF(tvec&**2,1,dfe).
SAVE {tvec,dfvec,pvec}
  /OUTFILE='Quade_out2'
  /VARIABLES=t,DF,pval.
END MATRIX.
OMSEND TAG=['Quade_NoMatrix'].
DATASET ACTIVATE Quade_temp1 WINDOW=ASIS.
OMS /SELECT ALL EXCEPT=WARNINGS 
  /IF COMMANDS=['Alter Type'] 
  /DESTINATION VIEWER=NO
  /TAG='Quade_NoAT'.
ALTER TYPE ALL (AMIN)
  /PRINT NONE.
OMSEND TAG=['Quade_NoAT'].""")
    from spss import CellText
    rlabels1=[]
    cur=spss.Cursor(isBinary=False)
    for i in range(0,spss.GetCaseCount()):
        datarow=cur.fetchone()
        rlabels1.append(datarow[0])
    cur.close()
    k=len(rlabels1)
    rlabels2=[]
    for i in range(k-1):
        for j in range(i+1,k):
            rlabels2.append(rlabels1[i] + " vs. " + rlabels1[j])
    spss.Submit(r"""
DATASET ACTIVATE Quade_out2 WINDOW=ASIS.
COMPUTE DF=RND(DF).
FORMATS t pval (F11.3) DF (F8.0).
OMS /SELECT ALL EXCEPT=WARNINGS 
  /IF COMMANDS=['Alter Type'] 
  /DESTINATION VIEWER=NO
  /TAG='Quade_NoAT'.
ALTER TYPE DF (A12)
  /PRINT NONE.
OMSEND TAG=['Quade_NoAT'].
VARIABLE LABELS t '     t' DF 'DF' pval 'P Value'.
EXECUTE.""")
    data2=[]
    cur=spss.Cursor(isBinary=False)
    for i in range(0,spss.GetCaseCount()):
        datarow=cur.fetchone()
        data2.append(datarow[0:])
    cur.close()
    def _flatten(seq):
        for item in seq:
            if spssaux._isseq(item):
                for subitem in _flatten(item):
                    yield subitem
            else:
                yield item
    data2=[item for item in _flatten(data2)]
    collabels2=[CellText.String(spss.GetVariableLabel(0)),CellText.String(spss.GetVariableLabel(1)),CellText.String(spss.GetVariableLabel(2))]
    spss.Submit("""
DATASET ACTIVATE Quade_out1 WINDOW=ASIS.
FORMATS F sig (F11.3) DFH DFE (F8.0).
VARIABLE LABELS F '          F' DFH 'DFH' DFE 'DFE' sig 'P Value'.
EXECUTE.
OMS
  /SELECT TABLES 
  /IF SUBTYPES=['Notes']
  /DESTINATION VIEWER=NO
  /TAG = 'Quade_NoNotes'.
OMS
  /SELECT TEXTS
  /IF LABELS=['Active Dataset']
  /DESTINATION VIEWER=NO
  /TAG = 'Quade_NoDSN'.""")
    cur=spss.Cursor(isBinary=False)
    data1=cur.fetchone()
    cur.close()
    spss.StartProcedure("Quade Nonparametric ANCOVA")
    table1 = spss.BasePivotTable("Quade Nonparametric Analysis of Covariance","Quade Nonparametric ANCOVA Test")
    table1.SimplePivotTable(rowdim = spss.GetVariableLabel(0),
                       rowlabels = [CellText.String("{:>14.3f}".format(data1[0]))],
                       coldim = "",
                       collabels = [CellText.String(spss.GetVariableLabel(1)),CellText.String(spss.GetVariableLabel(2)),CellText.String(spss.GetVariableLabel(3))],
                       cells = [CellText.Number(data1[1],spss.FormatSpec.Count),CellText.Number(data1[2],spss.FormatSpec.Count),CellText.Number(data1[3])])
    table2=spss.BasePivotTable("Pairwise Comparisons of Groups","Pairwise Comparisons")
    rowlabels2=[(CellText.String(rlabels2[i])) for i in range(len(rlabels2))]
    table2.SimplePivotTable(rowdim="Comparison",
                rowlabels=rowlabels2,
                coldim="",
                collabels=collabels2,
                cells=data2)
    spss.EndProcedure()
finally:
    spss.Submit("DATASET ACTIVATE %s WINDOW=ASIS" % activeds)
    try:
        spss.Submit("""
OMSEND TAG=['Quade_NoDSN'].
OMSEND TAG=['Quade_NoNotes'].
DATASET CLOSE Quade_temp1.
DATASET CLOSE Quade_out1.
DATASET CLOSE Quade_out2.
ERASE FILE='Quade_temp.sav'.""")
    except:
        pass
    spss.Submit("RESTORE")
end program.

PRESERVE.
begin program python3.
import tempfile, spss, random, spssaux
try:
    tempdir = tempfile.gettempdir()
    spss.Submit(r"""CD "%s".""" % tempdir)
    spss.Submit("""SET PRINTBACK=OFF MPRINT=OFF.""")
    activeds = spss.ActiveDataset()
    if activeds == "*":
        activeds = "D" + str(random.random()+.01)
        spss.Submit("DATASET NAME %s" % activeds)
    wtvar=spss.GetWeightVar()
    if wtvar == None:
        spss.Submit(r"""
USE ALL.
SAVE OUTFILE='Quade_temp.sav'
  /KEEP=MCID_Achieved Difference_T1S preop_T1_slope.
GET FILE='Quade_temp.sav'.""")
    else:
        spss.Submit(r"""
DO IF %s >= 1.""" % wtvar)
        spss.Submit(r"""
+ LOOP #i=1 TO %s.""" % wtvar)
        spss.Submit(r"""
XSAVE OUTFILE='Quade_temp.sav'
  /KEEP=MCID_Achieved Difference_T1S preop_T1_slope
  /DROP=%s.""" % wtvar)
        spss.Submit(r"""
+ END LOOP.
END IF.
EXECUTE.
GET FILE='Quade_temp.sav'.""")
    spss.Submit(r"""
COUNT miss__=MCID_Achieved Difference_T1S preop_T1_slope (MISSING).
SELECT IF miss__=0.
SORT CASES BY MCID_Achieved.
DATASET DECLARE Quade_temp1.
AGGREGATE
  /OUTFILE='Quade_temp1'
  /PRESORTED
  /BREAK=MCID_Achieved
  /N_BREAK=N.
OMS /SELECT ALL EXCEPT=WARNINGS 
  /IF COMMANDS=['Matrix'] 
  /DESTINATION VIEWER=NO
  /TAG='Quade_NoMatrix'.
DATASET DECLARE Quade_out1 WINDOW=HIDDEN.
DATASET DECLARE Quade_out2 WINDOW=HIDDEN.
MATRIX.
GET data
  /VARIABLES=MCID_Achieved Difference_T1S preop_T1_slope.
COMPUTE n=NROW(data).
COMPUTE g=DESIGN(data(:,1)).
COMPUTE dfh=NCOL(g)-1.
COMPUTE dfe=n-NCOL(g).
COMPUTE y=RNKORDER(data(:,2)).
COMPUTE ncov=NCOL(data)-2.
COMPUTE x=MAKE(n,1,1).
LOOP #j=1 TO ncov.
+ COMPUTE x={x,RNKORDER(data(:,#j+2))}.
END LOOP.
COMPUTE y=y-x*INV(SSCP(x))*T(x)*y.
COMPUTE sst=MSSQ(y).
COMPUTE sse=MSSQ(y-g*INV(SSCP(g))*T(g)*y).
COMPUTE ssh=sst-sse.
COMPUTE fstat=(ssh/dfh)/(sse/dfe).
COMPUTE pval=1-FCDF(fstat,dfh,dfe).
SAVE {fstat,dfh,dfe,pval}
   /OUTFILE='Quade_out1'
   /VARIABLES=F,DFH,DFE,sig.
COMPUTE countvec=T(CSUM(g)).
COMPUTE grpmean=T(g)*y&/countvec.
COMPUTE k=NROW(grpmean).
COMPUTE diff=MAKE(k*(k-1)/2,1,0).
COMPUTE sediff=MAKE(k*(k-1)/2,1,0).
COMPUTE h=1.
LOOP i=1 TO k-1.
+  LOOP j=i+1 TO k.
+    COMPUTE diff(h)=grpmean(i)-grpmean(j).
+    COMPUTE sediff(h)=SQRT((sse/dfe)*(1/countvec(i)+1/countvec(j))).
+    COMPUTE h=h+1.
+  END LOOP.
END LOOP.
COMPUTE tvec=diff&/sediff.
COMPUTE dfvec=MAKE(NROW(tvec),1,dfe).
COMPUTE pvec=MAKE(NROW(tvec),1,1)-FCDF(tvec&**2,1,dfe).
SAVE {tvec,dfvec,pvec}
  /OUTFILE='Quade_out2'
  /VARIABLES=t,DF,pval.
END MATRIX.
OMSEND TAG=['Quade_NoMatrix'].
DATASET ACTIVATE Quade_temp1 WINDOW=ASIS.
OMS /SELECT ALL EXCEPT=WARNINGS 
  /IF COMMANDS=['Alter Type'] 
  /DESTINATION VIEWER=NO
  /TAG='Quade_NoAT'.
ALTER TYPE ALL (AMIN)
  /PRINT NONE.
OMSEND TAG=['Quade_NoAT'].""")
    from spss import CellText
    rlabels1=[]
    cur=spss.Cursor(isBinary=False)
    for i in range(0,spss.GetCaseCount()):
        datarow=cur.fetchone()
        rlabels1.append(datarow[0])
    cur.close()
    k=len(rlabels1)
    rlabels2=[]
    for i in range(k-1):
        for j in range(i+1,k):
            rlabels2.append(rlabels1[i] + " vs. " + rlabels1[j])
    spss.Submit(r"""
DATASET ACTIVATE Quade_out2 WINDOW=ASIS.
COMPUTE DF=RND(DF).
FORMATS t pval (F11.3) DF (F8.0).
OMS /SELECT ALL EXCEPT=WARNINGS 
  /IF COMMANDS=['Alter Type'] 
  /DESTINATION VIEWER=NO
  /TAG='Quade_NoAT'.
ALTER TYPE DF (A12)
  /PRINT NONE.
OMSEND TAG=['Quade_NoAT'].
VARIABLE LABELS t '     t' DF 'DF' pval 'P Value'.
EXECUTE.""")
    data2=[]
    cur=spss.Cursor(isBinary=False)
    for i in range(0,spss.GetCaseCount()):
        datarow=cur.fetchone()
        data2.append(datarow[0:])
    cur.close()
    def _flatten(seq):
        for item in seq:
            if spssaux._isseq(item):
                for subitem in _flatten(item):
                    yield subitem
            else:
                yield item
    data2=[item for item in _flatten(data2)]
    collabels2=[CellText.String(spss.GetVariableLabel(0)),CellText.String(spss.GetVariableLabel(1)),CellText.String(spss.GetVariableLabel(2))]
    spss.Submit("""
DATASET ACTIVATE Quade_out1 WINDOW=ASIS.
FORMATS F sig (F11.3) DFH DFE (F8.0).
VARIABLE LABELS F '          F' DFH 'DFH' DFE 'DFE' sig 'P Value'.
EXECUTE.
OMS
  /SELECT TABLES 
  /IF SUBTYPES=['Notes']
  /DESTINATION VIEWER=NO
  /TAG = 'Quade_NoNotes'.
OMS
  /SELECT TEXTS
  /IF LABELS=['Active Dataset']
  /DESTINATION VIEWER=NO
  /TAG = 'Quade_NoDSN'.""")
    cur=spss.Cursor(isBinary=False)
    data1=cur.fetchone()
    cur.close()
    spss.StartProcedure("Quade Nonparametric ANCOVA")
    table1 = spss.BasePivotTable("Quade Nonparametric Analysis of Covariance","Quade Nonparametric ANCOVA Test")
    table1.SimplePivotTable(rowdim = spss.GetVariableLabel(0),
                       rowlabels = [CellText.String("{:>14.3f}".format(data1[0]))],
                       coldim = "",
                       collabels = [CellText.String(spss.GetVariableLabel(1)),CellText.String(spss.GetVariableLabel(2)),CellText.String(spss.GetVariableLabel(3))],
                       cells = [CellText.Number(data1[1],spss.FormatSpec.Count),CellText.Number(data1[2],spss.FormatSpec.Count),CellText.Number(data1[3])])
    table2=spss.BasePivotTable("Pairwise Comparisons of Groups","Pairwise Comparisons")
    rowlabels2=[(CellText.String(rlabels2[i])) for i in range(len(rlabels2))]
    table2.SimplePivotTable(rowdim="Comparison",
                rowlabels=rowlabels2,
                coldim="",
                collabels=collabels2,
                cells=data2)
    spss.EndProcedure()
finally:
    spss.Submit("DATASET ACTIVATE %s WINDOW=ASIS" % activeds)
    try:
        spss.Submit("""
OMSEND TAG=['Quade_NoDSN'].
OMSEND TAG=['Quade_NoNotes'].
DATASET CLOSE Quade_temp1.
DATASET CLOSE Quade_out1.
DATASET CLOSE Quade_out2.
ERASE FILE='Quade_temp.sav'.""")
    except:
        pass
    spss.Submit("RESTORE")
end program.

PRESERVE.
begin program python3.
import tempfile, spss, random, spssaux
try:
    tempdir = tempfile.gettempdir()
    spss.Submit(r"""CD "%s".""" % tempdir)
    spss.Submit("""SET PRINTBACK=OFF MPRINT=OFF.""")
    activeds = spss.ActiveDataset()
    if activeds == "*":
        activeds = "D" + str(random.random()+.01)
        spss.Submit("DATASET NAME %s" % activeds)
    wtvar=spss.GetWeightVar()
    if wtvar == None:
        spss.Submit(r"""
USE ALL.
SAVE OUTFILE='Quade_temp.sav'
  /KEEP=MCID_Achieved Difference_T1s_Minus_lordosis preop_T1SlopeminusC27_lordosis.
GET FILE='Quade_temp.sav'.""")
    else:
        spss.Submit(r"""
DO IF %s >= 1.""" % wtvar)
        spss.Submit(r"""
+ LOOP #i=1 TO %s.""" % wtvar)
        spss.Submit(r"""
XSAVE OUTFILE='Quade_temp.sav'
  /KEEP=MCID_Achieved Difference_T1s_Minus_lordosis preop_T1SlopeminusC27_lordosis
  /DROP=%s.""" % wtvar)
        spss.Submit(r"""
+ END LOOP.
END IF.
EXECUTE.
GET FILE='Quade_temp.sav'.""")
    spss.Submit(r"""
COUNT miss__=MCID_Achieved Difference_T1s_Minus_lordosis preop_T1SlopeminusC27_lordosis (MISSING).
SELECT IF miss__=0.
SORT CASES BY MCID_Achieved.
DATASET DECLARE Quade_temp1.
AGGREGATE
  /OUTFILE='Quade_temp1'
  /PRESORTED
  /BREAK=MCID_Achieved
  /N_BREAK=N.
OMS /SELECT ALL EXCEPT=WARNINGS 
  /IF COMMANDS=['Matrix'] 
  /DESTINATION VIEWER=NO
  /TAG='Quade_NoMatrix'.
DATASET DECLARE Quade_out1 WINDOW=HIDDEN.
DATASET DECLARE Quade_out2 WINDOW=HIDDEN.
MATRIX.
GET data
  /VARIABLES=MCID_Achieved Difference_T1s_Minus_lordosis preop_T1SlopeminusC27_lordosis.
COMPUTE n=NROW(data).
COMPUTE g=DESIGN(data(:,1)).
COMPUTE dfh=NCOL(g)-1.
COMPUTE dfe=n-NCOL(g).
COMPUTE y=RNKORDER(data(:,2)).
COMPUTE ncov=NCOL(data)-2.
COMPUTE x=MAKE(n,1,1).
LOOP #j=1 TO ncov.
+ COMPUTE x={x,RNKORDER(data(:,#j+2))}.
END LOOP.
COMPUTE y=y-x*INV(SSCP(x))*T(x)*y.
COMPUTE sst=MSSQ(y).
COMPUTE sse=MSSQ(y-g*INV(SSCP(g))*T(g)*y).
COMPUTE ssh=sst-sse.
COMPUTE fstat=(ssh/dfh)/(sse/dfe).
COMPUTE pval=1-FCDF(fstat,dfh,dfe).
SAVE {fstat,dfh,dfe,pval}
   /OUTFILE='Quade_out1'
   /VARIABLES=F,DFH,DFE,sig.
COMPUTE countvec=T(CSUM(g)).
COMPUTE grpmean=T(g)*y&/countvec.
COMPUTE k=NROW(grpmean).
COMPUTE diff=MAKE(k*(k-1)/2,1,0).
COMPUTE sediff=MAKE(k*(k-1)/2,1,0).
COMPUTE h=1.
LOOP i=1 TO k-1.
+  LOOP j=i+1 TO k.
+    COMPUTE diff(h)=grpmean(i)-grpmean(j).
+    COMPUTE sediff(h)=SQRT((sse/dfe)*(1/countvec(i)+1/countvec(j))).
+    COMPUTE h=h+1.
+  END LOOP.
END LOOP.
COMPUTE tvec=diff&/sediff.
COMPUTE dfvec=MAKE(NROW(tvec),1,dfe).
COMPUTE pvec=MAKE(NROW(tvec),1,1)-FCDF(tvec&**2,1,dfe).
SAVE {tvec,dfvec,pvec}
  /OUTFILE='Quade_out2'
  /VARIABLES=t,DF,pval.
END MATRIX.
OMSEND TAG=['Quade_NoMatrix'].
DATASET ACTIVATE Quade_temp1 WINDOW=ASIS.
OMS /SELECT ALL EXCEPT=WARNINGS 
  /IF COMMANDS=['Alter Type'] 
  /DESTINATION VIEWER=NO
  /TAG='Quade_NoAT'.
ALTER TYPE ALL (AMIN)
  /PRINT NONE.
OMSEND TAG=['Quade_NoAT'].""")
    from spss import CellText
    rlabels1=[]
    cur=spss.Cursor(isBinary=False)
    for i in range(0,spss.GetCaseCount()):
        datarow=cur.fetchone()
        rlabels1.append(datarow[0])
    cur.close()
    k=len(rlabels1)
    rlabels2=[]
    for i in range(k-1):
        for j in range(i+1,k):
            rlabels2.append(rlabels1[i] + " vs. " + rlabels1[j])
    spss.Submit(r"""
DATASET ACTIVATE Quade_out2 WINDOW=ASIS.
COMPUTE DF=RND(DF).
FORMATS t pval (F11.3) DF (F8.0).
OMS /SELECT ALL EXCEPT=WARNINGS 
  /IF COMMANDS=['Alter Type'] 
  /DESTINATION VIEWER=NO
  /TAG='Quade_NoAT'.
ALTER TYPE DF (A12)
  /PRINT NONE.
OMSEND TAG=['Quade_NoAT'].
VARIABLE LABELS t '     t' DF 'DF' pval 'P Value'.
EXECUTE.""")
    data2=[]
    cur=spss.Cursor(isBinary=False)
    for i in range(0,spss.GetCaseCount()):
        datarow=cur.fetchone()
        data2.append(datarow[0:])
    cur.close()
    def _flatten(seq):
        for item in seq:
            if spssaux._isseq(item):
                for subitem in _flatten(item):
                    yield subitem
            else:
                yield item
    data2=[item for item in _flatten(data2)]
    collabels2=[CellText.String(spss.GetVariableLabel(0)),CellText.String(spss.GetVariableLabel(1)),CellText.String(spss.GetVariableLabel(2))]
    spss.Submit("""
DATASET ACTIVATE Quade_out1 WINDOW=ASIS.
FORMATS F sig (F11.3) DFH DFE (F8.0).
VARIABLE LABELS F '          F' DFH 'DFH' DFE 'DFE' sig 'P Value'.
EXECUTE.
OMS
  /SELECT TABLES 
  /IF SUBTYPES=['Notes']
  /DESTINATION VIEWER=NO
  /TAG = 'Quade_NoNotes'.
OMS
  /SELECT TEXTS
  /IF LABELS=['Active Dataset']
  /DESTINATION VIEWER=NO
  /TAG = 'Quade_NoDSN'.""")
    cur=spss.Cursor(isBinary=False)
    data1=cur.fetchone()
    cur.close()
    spss.StartProcedure("Quade Nonparametric ANCOVA")
    table1 = spss.BasePivotTable("Quade Nonparametric Analysis of Covariance","Quade Nonparametric ANCOVA Test")
    table1.SimplePivotTable(rowdim = spss.GetVariableLabel(0),
                       rowlabels = [CellText.String("{:>14.3f}".format(data1[0]))],
                       coldim = "",
                       collabels = [CellText.String(spss.GetVariableLabel(1)),CellText.String(spss.GetVariableLabel(2)),CellText.String(spss.GetVariableLabel(3))],
                       cells = [CellText.Number(data1[1],spss.FormatSpec.Count),CellText.Number(data1[2],spss.FormatSpec.Count),CellText.Number(data1[3])])
    table2=spss.BasePivotTable("Pairwise Comparisons of Groups","Pairwise Comparisons")
    rowlabels2=[(CellText.String(rlabels2[i])) for i in range(len(rlabels2))]
    table2.SimplePivotTable(rowdim="Comparison",
                rowlabels=rowlabels2,
                coldim="",
                collabels=collabels2,
                cells=data2)
    spss.EndProcedure()
finally:
    spss.Submit("DATASET ACTIVATE %s WINDOW=ASIS" % activeds)
    try:
        spss.Submit("""
OMSEND TAG=['Quade_NoDSN'].
OMSEND TAG=['Quade_NoNotes'].
DATASET CLOSE Quade_temp1.
DATASET CLOSE Quade_out1.
DATASET CLOSE Quade_out2.
ERASE FILE='Quade_temp.sav'.""")
    except:
        pass
    spss.Submit("RESTORE")
end program.
